define(function(require, exports){
	// var $ = require('jquery');
	var pubjs = require('pubjs');
	var popwin = require('@base/dialog').base;
	var util = require('util');

	// 创意包审核弹层
	var VerityWin = popwin.extend({
		init:function(config){
			config = pubjs.conf(config, {
				'title': LANG("审核状态"),
				'size': 'xl'
			});

			this.Super('init', arguments);
		},
		afterBuild:function(){
			this.Super('afterBuild', arguments);
			var id = 0;
			var el = this.getContainer();
			var exchanger = pubjs.config('exchange');
			var metrics = [];
			util.each(exchanger, function(data){
				metrics.push({
					name: data.id,
					text: LANG(data.name),
					render: 'renderStatus',
					headerRender: 'renderHeader',
					align: 'center',
					param: data.alias_id || data.id
				});
			}, this);
			metrics.push({
				align: 'center',
				name: 'no_exchange',
				text: LANG('没有渠道审核结果'),
				param: 'no_exchange'
			});	

			this.createAsync('grid', 'sweety/grid/verify.creative', {
				'target': el,
				'metrics': metrics,
				'hasRefresh': false,
				'eventDataLoad': true,
				'param': {'SweetyId': +id},
				'auto_load': false,
				'pager': {
					size: 7
				}
			});

		},
		afterBuildTemplate: function(){
		},
		setParam: function(id, title, QualificationId){
			if(this.$.grid)
			{
				this.$.grid.setParam({
					'SweetyId': +id,
					'QualificationId': +QualificationId
				});
			}
			this.setTitle(title+'(ID:'+id+')'+LANG('-审核状态'));
			return this;
		},
		onOk: function(){
			this.hide();
			return false;
		},
		reset: function() {
			this.$.grid.reload();
			return this;
		},
		onGridDataLoad: function(ev)
		{
			var data = ev.param;
			var channel_ids = data.Channel_Ids || [];
			var showIds = [];
			var hideIds = [];
			var allIds = [];
			var exchange = pubjs.config('exchange');
			// 判断是否有审核结果
			util.each(exchange, function(item)
			{
				var id = item.id;
				allIds.push(id);
				// 有审核结果的渠道，显示
				if (channel_ids.indexOf(+id) != -1)
				{
					showIds.push(id);
				}
				// 无审核结果的渠道，隐藏
				else
				{
					hideIds.push(id);
				}
			}, this);
			
			if (data.Channel_Ids && data.Channel_Ids.length)
			{
				// 有审核结果的渠道，显示
				this.$.grid.toggleColumn(showIds, true);
				// 无审核结果的渠道，隐藏
				this.$.grid.toggleColumn(hideIds, false);
				this.$.grid.toggleColumn('no_exchange', false);
			}
			//如果一个审核结果都没有，则显示全部渠道，避免显示问题。
			else
			{
				this.$.grid.toggleColumn(allIds, false);
				this.$.grid.toggleColumn('no_exchange', true);
			}
		}
	});

	exports.verityWin = VerityWin;
});
